#include <stdio.h>
#include <unistd.h>

int g_val = 0;

int main()
{
    pid_t id = fork();
    if (id == 0)
    {
        // 子进程
        int cnt = 0;
        while (1)
        {
            printf("I am child,  pid: %d, ppid: %d, g_val: %d, &g_val: %p\n", getpid(), getppid(), g_val, &g_val);
            sleep(1);
            cnt++;
            if (cnt == 3)
            {
                g_val = 100;
                printf("change success, g_val: 0 -> 100\n");
            }
        }

    }
    else 
    {
        // 父进程 
        while (1)
        {
            printf("I am parent, pid: %d, ppid: %d, g_val: %d, &g_val: %p\n", getpid(), getppid(), g_val, &g_val);
            sleep(1);
        }
    }
    return 0;
}
